package com.zjhn.ds.controller.pc;

import com.alibaba.fastjson.JSON;
import com.zjhn.ds.common.BizResult;
import com.zjhn.ds.common.PageResult;
import com.zjhn.ds.domain.dto.pc.PcMonitorDetailDto;
import com.zjhn.ds.domain.dto.pc.PcMonitorDto;
import com.zjhn.ds.domain.dto.pc.SpotCheckDetailDto;
import com.zjhn.ds.domain.dto.pc.SpotCheckStatisticsDto;
import com.zjhn.ds.domain.dto.pc.StationStatusDto;
import com.zjhn.ds.domain.vo.CapacityStatisticsOutVo;
import com.zjhn.ds.domain.vo.MaintenanceChangeVo;
import com.zjhn.ds.domain.vo.MonthDailyDataVo;
import com.zjhn.ds.domain.vo.StaffInfoVo;
import com.zjhn.ds.param.CapacityStatisticsParam;
import com.zjhn.ds.param.MaintenanceChangePageParam;
import com.zjhn.ds.param.MonthDailyStatisticsParam;
import com.zjhn.ds.param.PcMonitorPageParam;
import com.zjhn.ds.param.SpotCheckDetailParam;
import com.zjhn.ds.param.SpotCheckStatisticsParam;
import com.zjhn.ds.param.StationRecordMonitorParam;
import com.zjhn.ds.param.StationStatusParam;
import com.zjhn.ds.param.UpdateCapacityStatisticsParam;
import com.zjhn.ds.param.WeavingStaffPageParam;
import com.zjhn.ds.service.MaintenanceChangeService;
import com.zjhn.ds.service.MonitorService;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.controller.pc
 * @Author: sxt
 * @CreateTime: 2023-11-22  14:57
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/jlw/monitor")
@Api(tags = "pc端监控相关接口")
public class MonitorController {

    @Resource
    private MonitorService monitorService;

    @Resource
    private MaintenanceChangeService maintenanceChangeService;

    @ApiOperation("pc端机台监控页面")
    @PostMapping("/pcStationMonitor")
    public BizResult<PageResult<PcMonitorDto>> pcStationMonitor(@RequestBody @Valid PcMonitorPageParam param) {
        log.info("====[INFO]=========MonitorController====pcStationMonitor param:{}", JSON.toJSONString(param));
        return monitorService.pcStationMonitor(param);
    }

    @ApiOperation("pc端机台时长监控页面")
    @PostMapping("/stationRecordMonitor")
    public BizResult<PcMonitorDetailDto> stationRecordMonitor(@RequestBody @Valid StationRecordMonitorParam param) {
        log.info("====[INFO]=========MonitorController====stationRecordMonitor param:{}", JSON.toJSONString(param));
        return monitorService.stationRecordMonitor(param);
    }

    @ApiOperation("pc端机台监控页面获取机台状态信息")
    @PostMapping("/stationStatus")
    public BizResult<List<StationStatusDto>> stationStatus(@RequestBody @Valid StationStatusParam param) {
        log.info("====[INFO]=========MonitorController====stationStatus param:{}", JSON.toJSONString(param));
        return monitorService.stationStatus(param);
    }


    @ApiOperation("pc端机台时长监控页面导出")
    @PostMapping("/stationRecordMonitorExport")
    public BizResult<?> stationRecordMonitorExport(@RequestBody @Valid StationRecordMonitorParam param, HttpServletResponse response) {
        log.info("====[INFO]=========MonitorController====stationRecordMonitorExport param:{}", JSON.toJSONString(param));
        return monitorService.stationRecordMonitorExport(param, response);
    }

    @ApiOperation("pc端编制抽检明细报表")
    @PostMapping("/spotCheckDetail")
    public BizResult<PageResult<SpotCheckDetailDto>> spotCheckDetail(@RequestBody @Valid SpotCheckDetailParam param) {
        log.info("====[INFO]=========MonitorController====spotCheckDetail param:{}", JSON.toJSONString(param));
        return monitorService.spotCheckDetail(param);
    }

    @ApiOperation("pc端编制抽检明细报表导出")
    @PostMapping("/spotCheckDetailExport")
    public BizResult<?> spotCheckDetailExport(@RequestBody @Valid SpotCheckDetailParam param, HttpServletResponse response) {
        log.info("====[INFO]=========MonitorController====spotCheckDetailExport param:{}", JSON.toJSONString(param));
        return monitorService.spotCheckDetailExport(param, response);
    }

    @ApiOperation("pc端编制抽检统计报表")
    @PostMapping("/spotCheckStatistics")
    public BizResult<PageResult<SpotCheckStatisticsDto>> spotCheckStatistics(@RequestBody @Valid SpotCheckStatisticsParam param) {
        log.info("====[INFO]=========MonitorController====spotCheckStatistics param:{}", JSON.toJSONString(param));
        return monitorService.spotCheckStatistics(param);
    }

    @ApiOperation("pc端编制抽检统计报表导出")
    @PostMapping("/spotCheckStatisticsExport")
    public BizResult<?> spotCheckStatisticsExport(@RequestBody @Valid SpotCheckStatisticsParam param, HttpServletResponse response) {
        log.info("====[INFO]=========MonitorController====spotCheckStatisticsExport param:{}", JSON.toJSONString(param));
        return monitorService.spotCheckStatisticsExport(param, response);
    }

    @ApiOperation("pc端编制抽检明细删除")
    @PostMapping("/spotCheckDetailDelete")
    public BizResult<?> spotCheckDetailDelete(@RequestParam(value = "sportCheckId") String spotCheckId) {
        log.info("====[INFO]=========MonitorController====spotCheckDetailDelete spotCheckId:{}", spotCheckId);
        return monitorService.spotCheckDetailDelete(spotCheckId);
    }

    // ======================================================

    @ApiOperation("查询织造车间用户信息")
    @PostMapping("/weavingStaff")
    public BizResult<PageResult<StaffInfoVo>> weavingStaff(@RequestBody @Valid WeavingStaffPageParam param) {
        log.info("====[INFO]========MonitorController====weavingStaff param：{}}", JSON.toJSONString(param));
        return maintenanceChangeService.weavingStaff(param);
    }

    @ApiOperation("按条件分页查询改机/维修信息")
    @PostMapping("/page")
    public BizResult<PageResult<MaintenanceChangeVo>> page(@RequestBody @Valid MaintenanceChangePageParam param) {
        log.info("====[INFO]========MonitorController====page param:{}", JSON.toJSONString(param));
        return maintenanceChangeService.page(param);
    }

    @ApiOperation("单日产能统计")
    @PostMapping("/capacityStatistics")
    public BizResult<CapacityStatisticsOutVo> capacityStatistics(@RequestBody @Valid CapacityStatisticsParam param) {
        log.info("====[INFO]========MonitorController====capacityStatistics param:{}", JSON.toJSONString(param));
        return maintenanceChangeService.capacityStatistics(param);
    }

    @ApiOperation("单月产能统计")
    @PostMapping("/monthDailyStatistics")
    public BizResult<List<MonthDailyDataVo>> monthDailyStatistics(@RequestBody @Valid MonthDailyStatisticsParam param) {
        log.info("====[INFO]========MonitorController====monthDailyStatistics param:{}", JSON.toJSONString(param));
        return maintenanceChangeService.monthDailyStatistics(param);
    }

    @ApiOperation("生成每日统计")
    @PostMapping("/generateDailyStatistics")
    public BizResult<?> generateDailyStatistics(@RequestBody @Valid CapacityStatisticsParam param) {
        log.info("====[INFO]========GroupController====generateDailyStatistics param:{}", JSON.toJSONString(param));
        return maintenanceChangeService.generateDailyStatistics(param);
    }

    @ApiOperation("单日产能更新")
    @PostMapping("/updateCapacityStatistics")
    public BizResult<?> updateCapacityStatistics(@RequestBody @Valid UpdateCapacityStatisticsParam param) {
        log.info("====[INFO]========MonitorController====updateCapacityStatistics param:{}", JSON.toJSONString(param));
        return maintenanceChangeService.updateCapacityStatistics(param);
    }

}
